#include<bits/stdc++.h>
using namespace std;
int a[100000005]={0},b[100000005]={0},oulap;
void prime(int n){
	b[0]=1;
	b[1]=1;
	for(int i=2;i<n;i++){
		if(!b[i]) a[++a[0]]=i;
		for(int j=1;j<=a[0]&&a[j]*i<n;j++){
			b[a[j]*i]=1;
			if(i%a[j]==0) break;
		}
	}
}
int oula(int n){
	int ans=n;
	for(int i=1;i<a[0];i++){
		if(n%a[i]==0) ans=ans-ans/a[i];
	}
	if(ans==n) return ans-1;
	return ans;
}
long long qpow(long long x,long long y,long long mod){
	long long ans=1;
	while(y>0){
		if(y&1) ans=(ans*x)%mod;
		x=(x*x)%mod;
		y>>=1;
	}
	return ans;
}
void inv(int i,int n,int p){
	if(i>n) return;
	long long ans=qpow((long long)i,(long long)oulap-1,(long long)p);
	printf("%lld\n",ans);
	inv(i+1,n,p);
}
int main(){
	int n,p;
	scanf("%d%d",&n,&p);
	prime(n);
	oulap=oula(p);
	inv(1,n,p);
	return 0;
}
